package com.ptszyxx.popose.module.main.report;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;
import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.constants.BundleConstant;
import com.ptszyxx.popose.databinding.FragmentReportBinding;
import com.ptszyxx.popose.module.main.report.vm.ReportVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.utils.YCollectionUtil;
import com.ysg.widget.flow.TagFlowLayout;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 举报
 */
public class ReportFragment extends BaseFragment<FragmentReportBinding, ReportVM> {
    private List<String> list = new ArrayList<>();

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_report;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public ReportVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(ReportVM.class);
    }

    @Override
    public void initParam() {
        super.initParam();
        Bundle bundle = getArguments();
        if (bundle != null){
            viewModel.userId = bundle.getString(BundleConstant.USER_ID);
        }
    }

    @Override
    public void initView() {
        super.initView();
        String[] reportTypeArray = getResources().getStringArray(R.array.report_type_array);
        if (YCollectionUtil.isNotEmpty(reportTypeArray)){
            for (String type: reportTypeArray) {
                list.add(type);
            }
            binding.flowlayout.setData(list, null);
            binding.flowlayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
                @Override
                public void onSelected(Set<Integer> selectPosSet) {
                    for (Integer i: selectPosSet){
                        viewModel.feedbackType = (i + 1) + "";
                    }
                }
            });
        }
    }
}
